/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-09-05
 * Time:22:24
 */

/**
 * 力扣1154:一年中的第几天
 */
public class dayOfYear {
    public int dayOfYear(String date) {
                                        //字符串的截取
        //因为给的是2019-01-09这种形式
        int year = Integer.parseInt(date.substring(0, 4));
        int month = Integer.parseInt(date.substring(5, 7));
        int day = Integer.parseInt(date.substring(8));

        int[] amount = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        //润年
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            ++amount[1];
        }

        int ans = 0;
        for (int i = 0; i < month - 1; ++i) {
            ans += amount[i];
        }
        return ans + day;
    }
}
